<?
include('../controller/handler.php');
include('../controller/twitwords.php');
include('../controller/twitter.php');
include('../scaffold/user.php');
include('../scaffold/tag.php');

$hd = new Handler();
$tw = new Twitwords();
$base_url = $hd->getBaseURL();
$hd->openDB();
$adds = $tw->parseTwitterData($hd);
$page = (isset($_GET['page']) && $_GET['page']>1)? $_GET['page'] : 1;
$tags_number = $tw->getTagsNumber();
$quantity = $hd->getTagsPerPage();
$offset = ($page-1)*$quantity;
$tags = $tw->loadAllTags($offset, $quantity);
$hd->closeDB();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<link rel="alternate" type="application/rss+xml" href="<?echo $base_url;?>rss/twitwords" />
	<?
	/****************
	 * HEAD MODULE
	 ***************/
	include('../module/head.inc.php');
	?>

	<title><?echo $hd->getTitle();?> - Home</title>
	
</head>

<body>
<?
/****************
 * HEADER MODULE
 ***************/
include('../module/header.inc.php');
?>
<div id="container">
	<?
	/****************
	 * SEARCH MODULE
	 ***************/
	include('../module/search.inc.php');
	?>
	<?
	if(count($tags)==0) echo "<h1>No tag to show you...</h1>";
	$i = 0;
	foreach($tags as $tag) {
		$i++;
		$style = ($i%2==0)? "even" : "odd";
		?>
		<div class="tag <?echo $style;?>">
		<img class="avatar" src="<?echo $tag->getUser()->getImage();?>" alt="Profile image" />
		<a class="username" href="<?echo $base_url;?>user/<?echo $tag->getUser()->getUsername();?>">
			<?echo $tag->getUser()->getUsername();?>
		</a> <!-- <span class="light">{ is a }</span> -->
		<p class="text"><?echo $tag->getTag();?></p>
		<p class="date"><?echo $hd->deltaToTime(time(), strtotime($tag->getDate()));?></p>
		</div>
		<?
	}
	?>
	<?
	if($hd->displayProgressBar()) {?>
	<div id="progress"><div id="bar"><?//echo $msg;?></div></div>
	<script type="text/javascript">
	//<![CDATA[
		var progress = new ProgressBar('progress', 'bar', { 
			frequency:1,
			total:500,
			timestamp:<?echo time();?>,
			last:<?echo $hd->getLastTimestamp();?>,
			timeout:<?echo $hd->getTimeout();?>,
			adds:<?echo $adds;?>
		});
		progress.start();
	//]]>
	</script>
	<?}?>
	
	<div id="credits"><?echo $hd->getCredits();?></div>
</div>
<div id="footer">
	<div id="nav">
		<?if($page>1) {?><a href="<?echo $base_url?>home/page:<?echo $page-1;?>">&larr; newer</a> <?}?>
		{ <? echo $tags_number;?> tags }
		<?if($tags_number>$offset+$quantity) {?><a href="<?echo $base_url?>home/page:<?echo $page+1;?>">older &rarr;</a><?}?>
	</div>
	<?
	/****************
	 * FOOTER MODULE
	 ***************/
	include('../module/footer.inc.php');
	?>
</div>
<?include('../module/analytics.inc.php');?>
</body>
</html>
